<template>
	<div>
		<div class='metamask-info'>
			<div>钱包数据</div>
			<p>状态: {{ isInjected ? '已连接' : '连接失败' }}</p>
			<p>钱包地址: {{ fromAddress }}</p>
		</div>
	</div>
</template>

<script>
	import web3 from 'web3'
	import {
		newBlockchainConnection
	} from '../../../util/getWeb.js'
	import {
		Toast
	} from 'vant'
	export default {
		name: 'casino-dapp',
		data() {
			return {
				isInjected: false, // 连接状态
				fromAddress: '', // 钱包地址
				WEB: ''
			}
		},
		mounted() {
			this.WEB = newBlockchainConnection(web3.givenProvider)
			console.log(this.WEB)
			if (this.WEB) {
				this.isInjected = true
			} else {
				this.isInjected = false
			}
			this.fn()
		},
		methods: {
			fn() {
				let that = this
				this.WEB.eth.requestAccounts().then((res, err) => {
					if (!err) {
						that.fromAddress = res[0]
					}
				})
			}
		}
	}
</script>

<style scoped>
	* {
		color: #444444;
	}
</style>
